package org.ax.controller.employ;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ax.data.Result;
import org.ax.pojo.employ.Department;
import org.ax.pojo.plan.Task;
import org.ax.service.employ.DepartmentService;
import org.ax.service.plan.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-16:42
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @RequestMapping("/find")
    public ModelAndView find(){
        return new ModelAndView("employ/department");
    }
    @Autowired
    DepartmentService departmentService;
    @Autowired
    Result result;
    @GetMapping("/list")
    public Result search(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int limit){
        Page<Department> departmentList = departmentService.findDepartmentList(new Page(page, limit));
        result.setData(departmentList.getRecords());
        result.setCount(departmentList.getTotal());
        return result;
    }
    @PostMapping("/add")
    public Result add(Department department){
        result.setMsg(departmentService.addDepartment(department)?"添加成功":"添加失败");
        return result;

    }
    @PostMapping("/update")
    public Result update(Department department){
        result.setMsg(departmentService.updateDepartment(department)?"修改成功":"修改失败");
        return result;

    }
    @GetMapping("/patchDel")
    public Result patchDel(String[] ids){
        result.setMsg(departmentService.deletesDepartment(ids)?"批量删除成功":"批量删除失败");
        return result;
    }
    @GetMapping("/departmentList")
    public Result departmentList(){
        result.setData(departmentService.availableDepartment());
        return result;
    }
}
